/*******************************************************************************
 * Copyright 2011 Towee.net
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 *******************************************************************************/
package net.towee.client.managers;

import java.util.LinkedList;
import java.util.List;

import net.towee.client.event.core.NodeReceivedEvent;
import net.towee.client.event.core.NodesMovedEvent;
import net.towee.client.event.core.NodesRemovedEvent;
import net.towee.client.event.core.NodesTrashEvent;
import net.towee.model.repo.NodeData;

import com.google.gwt.user.client.rpc.AsyncCallback;

/**
 * This interface define reposetory's tree Nodes data manager.
 * 
 * <ul>The implementation MUST handler this PUSH events:
 * <li>New node, or renamed node - {@link NodesReceivedEvent}</li>
 * <li>Delete node - {@link NodesRemovedEvent}</li>
 * <li>Trash node - {@link NodesTrashEvent}</li>
 * <li>Move node - {@link NodesMovedEvent}</li>
 * </ul>
 *
 * @author viiv.c58@gmail.com (Artem Artem'ev)
 */
public interface NodesManager {
	/**
	 * Get root nodes of given group
	 * 
	 * @param groupId
	 * @param handler
	 */
	public void getRootNodes(String groupId, AsyncCallback<List<NodeData>> handler);

	/**
	 * Get nodes by parent node id
	 * @param groupId TODO
	 * @param parentNodeId
	 * @param handler
	 */
	public void getSubTree(String groupId, String parentNodeId, AsyncCallback<List<NodeData>> handler);

	/**
	 * Get nodes by given path
	 * @param groupId TODO
	 * @param path
	 * @param handler
	 */
	public void getSubTreeByPath(String groupId, String path, AsyncCallback<List<NodeData>> handler);

	/**
	 * Get all subtrees to given path. For example if path was a/b/c/d it return
	 * all nodes by path a/, then a/b/, then a/b/c, and then a/b/c/d.
	 * @param groupId TODO
	 * @param path
	 * @param handler
	 */
	public void getSubTreesToPath(String groupId, String path, AsyncCallback<List<NodeData>> handler);

	/**
	 * Get node with given node id
	 * 
	 * @param nodeId
	 * @param groupId TODO
	 * @param handler
	 */
	public void getNode(String nodeId, String groupId, AsyncCallback<NodeData> handler);

	/**
	 * Save new node data. It set in node ID and invoke success method
	 * in handler.
	 * 
	 * On success it fire an event {@link NodeReceivedEvent}
	 * 
	 * @param node
	 */
	public void saveNode(NodeData node, AsyncCallback<NodeData> handler);

	/**
	 * Rename node with given nodeId
	 * 
	 * On success it fire an event {@link NodeReceivedEvent}
	 * @param groupId TODO
	 * @param nodeId
	 * @param newName
	 */
	public void renameNode(String groupId, String nodeId, String newName, AsyncCallback<Boolean> handler);

	/**
	 * Move nodes to new paren node
	 * 
	 * On success it fire an event {@link NodesMovedEvent}
	 * @param groupId TODO
	 * @param newParentNode
	 * @param nodeIds
	 */
	public void moveNodes(String groupId, String newParentNode, List<String> nodeIds, AsyncCallback<Boolean> handler);

	/**
	 * Remove nodes with given ids.
	 * 
	 * On success it fire an event {@link NodesRemovedEvent}
	 * @param groupId TODO
	 * @param nodeIds
	 */
	public void removeNode(String groupId, List<String> nodeIds, AsyncCallback<Boolean> handler);

	/**
	 * Put given nodes to trash
	 * 
	 * On success it fire an event {@link NodesTrashEvent}
	 * @param groupId TODO
	 * @param nodeIds
	 */
	public void putToTrash(String groupId, List<String> nodeIds, AsyncCallback<Boolean> handler);

	/**
	 * Check node existing in some group and in some parent node
	 * @param nodeName
	 * @param asyncCallback
	 */
	public void checkNodeExisting(String nodeName, String groupNode, String parentNode, AsyncCallback<Boolean> asyncCallback);
	
	/**
	 * Return list of nodes included in path to given node
	 * @param node
	 * @param asyncCallback
	 */
	public void getPathToNode(NodeData node, AsyncCallback<LinkedList<NodeData>> asyncCallback);
}
